package cn.tedu._05mvcboot05.controller;

import cn.tedu._05mvcboot05.common.respose.JsonResult;
import cn.tedu._05mvcboot05.common.respose.StatusCode;
import cn.tedu._05mvcboot05.mapper.UserMapper;
import cn.tedu._05mvcboot05.pojo.dto.UserArticleDTO;
import cn.tedu._05mvcboot05.pojo.dto.UserLoginDTO;
import cn.tedu._05mvcboot05.pojo.vo.UserVO;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.UserAccessorProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/v1/users/")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @ApiOperation("登录功能")
    @RequestMapping("login")
    public JsonResult login(@RequestBody UserLoginDTO userLoginDTO, @ApiIgnore HttpSession session){
        String username = userLoginDTO.getUsername();
        String password = userLoginDTO.getPassword();
        UserVO userVO = userMapper.selectUser(username,password);
        if (userVO==null){
            return new JsonResult(StatusCode.USERNAME_PASSWORD_ERROR);
        }
        session.setAttribute("user",userVO);
        return JsonResult.ok();

    }

    @ApiOperation("发表文章功能")
    @RequestMapping("selectByArticleId")
    public  JsonResult selectByArticleId(@RequestBody UserArticleDTO userArticleDTO,@ApiIgnore HttpSession session){
        UserVO userVO =(UserVO) session.getAttribute("user");
return JsonResult.ok();
    }


}
